<html>
<head>
    <title>新建/编辑 主题</title>
    <% include("base/meta.html"){} %>

</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                        <legend>新建/编辑 主题</legend>
                    </fieldset>
                </div>
                <div class="layui-card-body ">
                    <form class="layui-form layui-form-pane" action="" id="editForm">
                        <input type="hidden" name="id" id="id" value="${editData.id!}">

                        <div class="layui-form-item">
                            <input type="text" name="cname" id="cname" lay-verify="cname" autocomplete="off"
                                   placeholder="请输入中文描述"
                                   class="layui-input" value="${editData.cname!}">
                        </div>

                        <div class="layui-form-item">
                            <input type="text" name="ename" id="ename" lay-verify="ename" autocomplete="off"
                                   placeholder="请输入文件名称(不包含.css)"
                                   class="layui-input" value="${editData.ename!}">
                        </div>


                        <div class="layui-form-item">
                            <input type="text" name="desc" id="desc" lay-verify="desc" autocomplete="off"
                                   placeholder="请输入主题描述"
                                   class="layui-input" value="${editData.ename!}">
                        </div>

                        <div class="layui-form-item">
                            <label for="type" class="layui-form-label">主题类型</label>
                            <div class="layui-input-inline">
                                <%if(editData==null){%>
                                <select name="type">
                                    <option value="">-请选择-</option>
                                    <option value="view">前台</option>
                                    <option value="admin">后台</option>
                                </select>
                                <%}else{%>
                                <select name="type">
                                    <option value="">-请选择-</option>
                                    <option value="view"<%if(editData.type=="view"){%>selected <%}%> >前台</option>
                                    <option value="admin"<%if(editData.type=="admin"){%>selected <%}%> >后台</option>
                                </select>
                                <%}%>

                            </div>
                        </div>


                        <div class="layui-form-item">
                            <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="save">保存
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>


    layui.use(['form', 'layer', 'layedit'], function () {
        $ = layui.jquery;
        var form = layui.form;


        //自定义验证规则
        form.verify({
            cname: function (value) {
                if (value === undefined || value === '' || value.length === 0) {
                    return '中文描述不能为空';
                }
            },
            ename: function (value) {
                if (value === undefined || value === '' || value.length === 0) {
                    return '文件名称不能为空';
                }
            }

        });

        //监听提交
        form.on('submit(save)', function (data) {
            debugger
            $.ajax({
                cache: false,
                type: "POST",
                contentType: 'application/json',
                url: "/theme/addup",
                data: JSON.stringify(data.field),
                async: false,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg(data.message, {
                            time: 2000
                        });

                        self.setTimeout(function () {
                            $("#editForm")[0].reset();
                            layui.form.render();
                            $("#cname").val('');
                            $("#ename").val('');
                            $("#desc").val('');
                            try {
                                parent.layui.table.reload('themeList');
                            } catch (err) {
                            }
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 2000);


                    } else {
                        layer.msg(data.message);

                    }
                },
                error: function (data) {
                    layer.msg(data.message);
                }
            });

            return false;
        });
    });
</script>

</body>
</html>